package tk.xboot.boot.web;

import java.io.Serializable;

/**
 * A simple object wrapper for response web result.
 *
 * How to use the web result?
 *
 * First you should check http status is 200.
 * Second check if the WebResult.getData() is null, if the getData() is null,
 * you should getErrCode and getErrMsg() for more details of the response, or
 * use the data directly else.
 *
 * @Asin Liu
 * @since 1.1
 *
 * @param <T>
 */
public class WebResult<T> implements Serializable {

    private int errCode;
    private String errMsg;
    private T data ;

    public static <T> WebResult<T> ok(T t){
        WebResult wr = new WebResult<>();
        wr.setData(t);
        return wr;
    }

    public static <T> WebResult<T> err(int errCode){
        WebResult wr = new WebResult<>();
        wr.setErrCode(errCode);
        wr.setErrMsg("777");
        return wr;
    }

    public int getErrCode() {
        return errCode;
    }

    public void setErrCode(int errCode) {
        this.errCode = errCode;
    }

    public String getErrMsg() {
        return errMsg;
    }

    public void setErrMsg(String errMsg) {
        this.errMsg = errMsg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
